<template>
  <div class="">
    <!--头部导航-->
    <div class="top_nav_box">
      <div class="width_1108 margin_0_auto top_second_box">
      <div class="top_tab row width_1108">
        <div class="logo_box col-md-5 text-left">
          <router-link to="/home"><img src="http://image.xuemei99.com/logo_icon_home.png" alt=""></router-link>
        </div>
        <ul class="tab_box text-center col-md-5 row">
          <li class="col-md-3">
            <router-link to="/home" class="col_333">首页</router-link>
          </li>
          <li class="col-md-3 products_nav">
            产品中心
            <ul class="second_nav none bg_fff">
              <li>
                <router-link to="/huoke" class="col_333">获客宝</router-link>
              </li>
              <li>
                <router-link to="/market" class="col_333">销售宝</router-link>
              </li>
              <!--<li><router-link to="/extension" class="col_333">推广宝</router-link></li>-->
              <li>
                <router-link to="/kelianke" class="col_333">客连客</router-link>
              </li>
            </ul>
          </li>
          <li class="col-md-3 agent_li">
            <router-link to="/agent" class="col_333">加盟合作</router-link>
          </li>
          <li class="col-md-3">
            <router-link to="/contacts" class="col_333">联系我们</router-link>
          </li>
          <!--<li class="col-md-1"><router-link to="/huoke">获客</router-link></li>-->
        </ul>

        <!--用户中心-->
        <ul class="nav navbar-nav navbar-right" v-if="login_true">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle user_id" data-toggle="dropdown" role="button" aria-haspopup="true"
               aria-expanded="false" id="user_name">{{user_name}} <span class="caret"></span></a>
            <ul class="dropdown-menu user_menu" style="border-radius: 6px">
              <span class="glyphicon glyphicon-triangle-top user_nemu_top" aria-hidden="true"></span>
              <li class="hover_bg_2577EF">
                <router-link to="/center">个人中心</router-link>
              </li>
              <li class="hover_bg_2577EF" v-show="manager">
                <router-link to="/manager">管理后台</router-link>
              </li>
              <li class="hover_bg_2577EF">
                <router-link to="/revisePassword">修改密码</router-link>
              </li>
              <li class="hover_bg_FF7A7A" @click="to_login_out"><span class="sign_out">退出</span></li>
            </ul>
          </li>
        </ul>

        <!--登陆注册-->
        <div class="sign_box col-md-2" v-else>
          <button type="button" class="btn border_2577EF col_2577EF bg_fff top_login_btn" @click="to_login">登录</button>
          <router-link to="/register">
            <button type="button" class="btn bg_2577EF border_2577EF col_fff margin_left_20 top_register_btn">注册
            </button>
          </router-link>
        </div>
      </div>
      </div>
    </div>
    <!--移动端头部-->
    <nav class="navbar navbar-fixed-top navbar-has-shadow bg_fff mobile_nav">
      <div class="container">
        <div class="navbar-header mobile_nav_header" style="margin-left: 0;margin-right: 0">
          <!--右侧按钮-->
          <button type="button" class="navbar-toggle collapsed"
                  :class="switch_btn_status == true ? 'mobile_menu_open' : 'mobile_menu_close'"
                  @click="switch_btn($event)">
            <span class="sr-only"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <!--logo-->
          <a class="navbar-brand" href="/">
            <img src="http://image.xuemei99.com/logo_icon_home.png" class="navbar-brand__img mobile_logo" alt="">
          </a>
        </div>
      </div><!-- /.container -->
    </nav>

    <!--侧边遮罩与导航-->
    <div class="mobile_mask" v-show="!switch_btn_status" @click="switch_btn($event)"></div>
    <div class="mobile_right_box bg_fff">
      <!--首页-->
      <div class="mobile_nav_item">
        <div class="nav_left_icon home_icon float_left"></div>
        <div class="nav_center_txt float_left" @click="switch_btn($event)"><router-link to="/home">首页</router-link></div>
        <div class="nav_right_icon float_left "></div>
      </div>

      <!--产品中心-->
      <div class="panel">
        <div class="mobile_nav_item mobile_product_bg clear" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
          <div class="nav_left_icon products_icon float_left"></div>
          <div class="nav_center_txt float_left" @click="panel_collapse_click">
            <a role="button" class="col_333">产品中心</a>
          </div>
          <div class="nav_right_icon float_left" :class="panel_collapse_up == true ? 'nav_right_icon_up' : 'nav_right_icon_down'"></div>
        </div>
        <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body text-left nav_panel_body">
            <div class="products_item" @click="switch_btn($event)"><router-link to="/huoke">获客宝</router-link></div>
            <div class="products_item" @click="switch_btn($event)"><router-link to="/market">销售宝</router-link></div>
            <!--<div class="products_item" @click="switch_btn($event)"><router-link to="/extension">推广宝</router-link></div>-->
            <div class="products_item" @click="switch_btn($event)"><router-link to="/kelianke">客连客</router-link></div>
          </div>
        </div>
      </div>

      <!--加盟合作-->
      <div class="mobile_nav_item">
        <div class="nav_left_icon agent_icon float_left"></div>
        <div class="nav_center_txt float_left" @click="switch_btn($event)"><router-link to="/agent">加盟合作</router-link></div>
        <div class="nav_right_icon float_left "></div>
      </div>

      <!--联系我们-->
      <div class="mobile_nav_item">
        <div class="nav_left_icon contact_icon float_left"></div>
        <div class="nav_center_txt float_left" @click="switch_btn($event)"><router-link to="/contacts">联系我们</router-link></div>
        <div class="nav_right_icon float_left "></div>
      </div>

    </div>

    <!--中间展示-->
    <div class="body_view">
      <router-view></router-view>
    </div>



    <!--立即咨询按钮-->
    <div class="bg_2577EF col_fff font_16 mobile_consult_box" @click="show_mobile_consult">
      立即咨询
    </div>

    <!--遮罩-->
    <div class="mobile_mask" v-show="mask_show" @click="close_mobile_consult"></div>
    <!--立即咨询弹出框-->
    <div class="bg_fff mobile_consult_modal">
      <div class="consult_title"><p>联系我们</p><div class="consult_modal_close" @click="close_mobile_consult"></div></div>
      <div class="consult_body" v-if="sub_consult">
        <p class="font_14 margin_top_20">请拨打咨询热线</p>
        <p class="font_20 col_2577EF padding_bottom_10">021-67680297</p>
        <p class="consult_line"></p>
        <p class="font_14 margin_top_20">或者填写您的联系方式，我们会主动与您联系：</p>
        <input type="text" class="margin_top_6 consult_inp" id="mobile_user_name" maxlength="10" placeholder="称呼">
        <input type="text" class="margin_top_16 consult_inp" id="mobile_contact_tel" maxlength="11" placeholder="手机号码">
        <div class="margin_top_20 mobile_qrcode_box">
          <input type="number" class="font_16 padding_left_10 vertical_middle" id="mobile_contact_qrcode" placeholder="短信验证码">
          <button type="button" class="bg_2577EF col_fff font_12" @click="message_qrcode_btn($event)">获取验证码</button>
        </div>
        <textarea cols="30" maxlength="100" class="margin_top_20 mobile_consult_textarea" id="mobile_contact_message"></textarea>
        <button type="button" class="col_fff bg_2577EF margin_top_20 margin_bottom_20 sub_mobile_consult" @click="sub_consult_btn">提交</button>
      </div>

      <div class="consult_body" v-else>
        <div class="mobile_cosult_success_cont">
          <div class="mobile_consult_success"></div>
          <p class="col_2577EF font_14 margin_top_12">感谢您的关注！</p>
          <div class="margin_top_20 col_666">
            <p class="margin_bottom_0">我们已收到您的咨询信息， </p>
            <p>客服将会在24小时内联系您。</p>
          </div>
        </div>
        <button type="button" class="col_999 bg_fff margin_top_20 margin_bottom_20 border_999 sub_mobile_consult" @click="close_mobile_consult">返回</button>
      </div>
    </div>
  </div>
</template>

<script>


  //注册组件
  export default {
    name:'index',
    components:{

    },
    methods: {
      //点击登陆
      to_login(){
        window.location.href = 'http://cas.xuemei99.com/web/cas/login?service=https%3A%2F%2Fwww.xuemei99.com%2Fweb%2Flogin%2F%3Fnext%3D%252F'
      },

      //点击退出跳转登陆
      to_login_out(){
        let that = this;
        window.location.href = 'https://www.xuemei99.com/web/logout/';
      },

      /**
       * 点击menu切换
       * 根据switch_btn_status判断
       * 显示/隐藏遮罩
       * 侧边栏滑动效果
       * **/
      switch_btn(eve){
        let that = this;
        if (that.switch_btn_status == true) {
          that.switch_btn_status = false;
          $(".mobile_right_box").animate({right: "0px"}, 500, "swing")
        } else {
          that.switch_btn_status = true;
          $(".mobile_right_box").animate({right: "-249px"}, 500, "swing")
        }
      },

      /**
       * 根据panel_collapse_up判断
       * 切换侧边导航上下箭头
       * **/
      panel_collapse_click(){
          let that = this;
          if (that.panel_collapse_up == true){
              that.panel_collapse_up = false;
          }else {
              that.panel_collapse_up = true;
          }
      },

      /**
       * 点击显示咨询弹出框
       * **/
      show_mobile_consult(){
          let that = this;
          that.mask_show = true;
          that.sub_consult = true;
          $(".mobile_consult_modal").animate({"height":'550px'},'500','swing');
      },

      /**
       * 短信验证码请求
       * **/
      message_qrcode_btn(e){
        let obj = window.event || e;
        let event_target = obj.target || obj.srcElement;
        let that = this;
        let countdown = 60;
        let user_phone_inp = $("#mobile_contact_tel").val();
        /**
         * 请求验证码
         * **/
        that.base.ajax_post('/site/get/mobile/msg/code',{"phone":user_phone_inp}, function (data) {
          if (data.status == 0) {
            /**
             * 请求成功，倒计时开始
             * **/
            settime(obj);
            function settime() {
              if (countdown == 0) {
                $(event_target).attr("disabled", false).text("获取验证码").removeClass("bg_B1B3B5").addClass("bg_2577EF");
                //按钮失效
                $(event_target).attr("disabled", false);
                countdown = 60;
                return;
              } else {
                $(event_target).attr("disabled", true).text(countdown + "s").removeClass("bg_2577EF").addClass("bg_B1B3B5");
                countdown--;
              }
              setTimeout(function () {
                settime(obj)
              }, 1000)
            }
          } else {
            alert(data.detail)
          }
        });
      },

      /**
       * 提交留言板数据
       * checkStringNull ：非空校验
       * 如果表单合法，则请求数据
       * **/
      sub_message_board(){

      },

      /**
       * 点击提交咨询内容
       * **/
      sub_consult_btn(){
        let that = this;
        let user_name = $("#mobile_user_name").val();
        let user_phone = $("#mobile_contact_tel").val();
        let message_qrcode = $("#mobile_contact_qrcode").val();
        let textarea_content = $("#mobile_contact_message").val();
        if (that.checkStringNull(user_name) == false && that.checkStringNull(user_phone) == false && that.checkStringNull(message_qrcode) == false && that.checkStringNull(textarea_content) == false) {
          that.base.ajax_post("/site/consult", {
            "name": user_name,
            "phone": user_phone,
            "code": message_qrcode,
            "content": textarea_content
          }, function (data) {
            if (data.status == 0) {
              that.sub_consult = false;
            } else {
              alert(data.detail);
            }
          })
        } else {
          alert("请完善信息再提交")
        }
      },

      /**
       * 关闭咨询弹出框
       * **/
      close_mobile_consult(){
          let that = this;
          that.mask_show = false;
          that.sub_consult = false;
          $(".mobile_consult_modal").animate({"height":0},'500','swing')
      }
    },
    data(){
        return{
          login_true: false,
//          login_true:true,
          user_name: "未登录",
          manager:false,
          switch_btn_status:true,
          panel_collapse_up:true,
          mask_show:false,
          sub_consult:false
        }
    },
    mounted(){
      let that = this;
      /**
       * 先获取cookie中的token和userid
       * 再在请求头设置，提交
       * 如果没有userid则没登陆状态
       * **/
      let user_id = $.cookie('userid');
      let user = $.cookie('user');
      if (that.checkStringNull(user_id) == false) {
        that.user_name = user;
        that.login_true = true;
      }
      //请求判断显示是否为管理员
      that.base.ajax_get('/site/verify/account', function (data) {
        if (data.status == 0) {
          that.manager = data.detail;
        }
      });

      //鼠标悬浮产品中心时，展示二级导航
      $('.tab_box .products_nav').hover(function () {
        $(this).find('.second_nav').animate({opacity: 'show', height: 'show'}, 200);
      }, function () {
        $('.second_nav').stop(true, true).hide();
      });

    }
  }
</script>

<style scoped>
  .user_id{
    height: 60px;
    line-height: 60px;
    padding-top: 0px;
    padding-bottom: 0px;
  }
  .top_login_btn:hover{
    background-color: #2577EF;
    color: #ffffff;
  }
  .top_register_btn:hover{
    background-color: #1364DB;
    color: #ffffff;
  }
  .user_menu{
    background-color: rgba(24,35,50,.8);
    margin-top: -6px;
    padding: 10px;
  }
  .user_nemu_top{
    position: absolute;
    top: -11px;
    right: 25px;
    z-index: 999;
    color: #182332;
    opacity: .8;
  }
  .user_menu li{
    width: 100%;
    color: #ffffff;
    font-size: 14px;
    height: 30px;
    line-height: 30px;
    padding-left: 10px;
    cursor: pointer;
    border-radius: 4px ;
  }
  .sign_out{
    padding: 3px 20px;
  }
  .hover_bg_2577EF:hover{
    background-color: #2577EF;
  }
  .hover_bg_FF7A7A:hover{
    background-color: #FF7A7A;
  }
  .user_menu li a{
    color: #ffffff;
  }
  .user_menu li a:hover{
    background: none;
  }

  .top_nav_box{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 999;
    height: 60px;
  }
  .top_second_box{
    position: absolute;
    top: 0;
    width: 100%;
    box-shadow: 0 2px 8px rgba(34,35,36,.1);
    z-index: 999;
    background-color: #ffffff;
  }
.top_tab{
  margin: 0 auto;
  height: 60px;
}
.tab_box{
  list-style: none;
  margin: 0;
  /*overflow: hidden;*/
}
.tab_box li{
  padding-left: 0;
  padding-right: 0;
}
.tab_box li a:hover{
  text-decoration: none;
  color: #2577EF;
}
.router-link-active{
  color: #2577EF;
}
.tab_box li{
  float: left;
  line-height: 60px;
}

.products_nav{
  position: relative;
}
.second_nav{
  padding: 0;
  position: absolute;
  top: 60px;
  left: 0;
  width: 100%;
  z-index: 999;
}
.second_nav li{
  text-align: center;
  width: 100%;
  height: 35px;
  line-height: 20px;
  float: none;
}
.second_nav li a:hover{
  color: #2577EF;
}


.logo_box{
  height: 60px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}
.logo_box img{
  height: 40px;
}
.sign_box{
  float: right;
  height: 60px;
  line-height: 60px;
  vertical-align: middle;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sign_box button{
  vertical-align: middle;
  width: 80px;
  height: 30px;
  line-height: 18px;
}
.body_view{
  margin-top: 60px;
  border: 1px solid rgba(255,255,255,0);
  box-sizing: border-box;
}
  .foot_view{
    margin-top: -10px;
  }
</style>
